#!/bin/sh

set -eu

AKTUALIZR_PTEST_PARALLEL_LEVEL=${AKTUALIZR_PTEST_PARALLEL_LEVEL:-2}

filter_logs() {
    awk '/^.*Test[[:space:]]*#[[:digit:]]+:/ {
        a = gensub(/^.*Test[[:space:]]*#[[:digit:]]+:[[:space:]]*([^[:space:]]+).*(Passed|Skipped|Not Run|Failed|Timeout|Exception)[[:space:]:].*$/, "\\2: \\1", "g");
        a = gensub(/^Passed/, "PASS", "g", a);
        a = gensub(/^(Skipped|Disabled)/, "SKIP", "g", a);
        a = gensub(/^(Not Run|Failed|Timeout|Exception)/, "FAIL", "g", a);
        print a;
    }'
}

cd build
ctest -j "$AKTUALIZR_PTEST_PARALLEL_LEVEL" -O /tmp/aktualizr-ptest.log --output-on-failure -LE 'noptest' 2> /dev/null | filter_logs
